﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZedGraph;
using CCWin;
using System.Threading;
using System.IO;
using Newtonsoft.Json;

namespace weiqijiance.国标自检类
{
    public partial class GBJZHX : CCSkinMain
    {
        public mainform m_mainform;

        public bool btingzhi = false;

        public float m_fspeed;
        public float fForce;
        public string sASMJGXZ;//是否进行结果修正
        public int iASMtdz;//ASM信号左通道
        public int iASMtdy;//ASM信号右通道
        public int iASMtdh;//ASM信号右通道
        public int iASMHWQ;//ASM到位红外
        public int iASMKZJSS;//ASM举升升
        public int iASMKZJSJ;//ASM举升降
        public int iASMSDtd;//车速信号接在那个通道

        DateTime dstartgcsj;
        DateTime dpinlv;
        public int igcsj;//划线计数
        public float DIW=100;
        public float fSpeedStrat;
        public float fSpeedEnd;
        public int fpow = 0;

        public float  fgonglv;
        public float fspeed;

        public double dli;
        public double dtime;
        public double dwc;

        public double dli25;
        public double dtime25;
        public double dwc25;

        double[] dtimex = new double[10000];
        double[] dSP = new double[10000];
        double[] dPW = new double[10000];
        double[] dFC = new double[10000];

        public Thread t1;
        public Thread t2;
        public Thread t3;
        public Thread t4;
        public Thread t5;


        public bool wancheng = false;

        public GBJZHX()
        {
            InitializeComponent();
        }
        #region 控件大小随窗体大小等比例缩放
        private float x;//定义当前窗体的宽度
        private float y;//定义当前窗体的高度
        private void setTag(Control cons)
        {
            foreach (Control con in cons.Controls)
            {
                con.Tag = con.Width + ";" + con.Height + ";" + con.Left + ";" + con.Top + ";" + con.Font.Size;
                if (con.Controls.Count > 0)
                {
                    setTag(con);
                }
            }
        }
        private void setControls(float newx, float newy, Control cons)
        {
            //遍历窗体中的控件，重新设置控件的值
            foreach (Control con in cons.Controls)
            {
                //获取控件的Tag属性值，并分割后存储字符串数组
                if (con.Tag != null)
                {
                    string[] mytag = con.Tag.ToString().Split(new char[] { ';' });
                    //根据窗体缩放的比例确定控件的值
                    con.Width = Convert.ToInt32(System.Convert.ToSingle(mytag[0]) * newx);//宽度
                    con.Height = Convert.ToInt32(System.Convert.ToSingle(mytag[1]) * newy);//高度
                    con.Left = Convert.ToInt32(System.Convert.ToSingle(mytag[2]) * newx);//左边距
                    con.Top = Convert.ToInt32(System.Convert.ToSingle(mytag[3]) * newy);//顶边距
                    Single currentSize = System.Convert.ToSingle(mytag[4]) * newy;//字体大小
                    con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
                    if (con.Controls.Count > 0)
                    {
                        setControls(newx, newy, con);
                    }
                }
            }
        }
        #endregion
        model.尾气自检.zjgcsj objgcsjhx = new model.尾气自检.zjgcsj();
        model.尾气自检.zjgcsj objgcsjnz = new model.尾气自检.zjgcsj();
        public void getpow(float start,float end,float diw,int szpow)
        {
            float fnz40 = 0, fnz25 = 0;
            {
                iniclass objini = new iniclass();
                objini.Ini(System.Windows.Forms.Application.StartupPath + "\\设备检定结果.ini");
                //float.TryParse(objini.ReadValue("内阻检定", "50内阻"), out fnz50);
                //float.TryParse(objini.ReadValue("内阻检定", "40内阻"), out fnz40);
                //float.TryParse(objini.ReadValue("内阻检定", "30内阻"), out fnz30);

                float.TryParse(objini.ReadValue("附加损失功率", "40内阻"), out fnz40);
                float.TryParse(objini.ReadValue("附加损失功率", "25内阻"), out fnz25);
            }

            m_mainform.DAC.PutVol(0);
            Thread.Sleep(1000);
            m_mainform.BianPinQi(true);
            Thread.Sleep(3000);
            m_mainform.BianPinQiSpeed(256 * 40);//设置频率
            float flichazhi = 0;

            dpinlv = DateTime.Now;
            while (true)
            {
                Thread.Sleep(20);
                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iASMSDtd]);
                float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataSU[iASMtdz]) - m_mainform.DAC.getjsz("测功力左",  m_mainform.DAC.fAIDataZero[iASMtdz]);
                float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataSU[iASMtdy]) - m_mainform.DAC.getjsz("测功力右",  m_mainform.DAC.fAIDataZero[iASMtdy]);
                float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataSU[iASMtdh]) - m_mainform.DAC.getjsz("测功力后",  m_mainform.DAC.fAIDataZero[iASMtdh]);

                fForce = fzou + fyou + fhou;
                if (fForce < 0)
                {
                    fForce = 0;
                }

                if (m_fspeed > start + 8)
                {
                    m_mainform.BianPinQi(false); ;//关闭电源电源
                    break;
                }
                flichazhi = fForce;
                if (flichazhi < 0)
                    flichazhi = 0;

                fgonglv = (flichazhi * m_fspeed) / 360;
                fspeed = m_fspeed;
                //  xianshiGL();
                xianshiSpeed();
                //过程数据
                if (DateDiff(DateTime.Now, dpinlv) > 500)
                {
                    dSP[igcsj] = (double)fspeed;
                    dPW[igcsj] = fForce * fspeed / 360;
                    dFC[igcsj] = fForce;
                    dtimex[igcsj] = DateDiff(DateTime.Now, dstartgcsj) / 1000;
                    WriteGraph(zedGraphControl1, dSP, dPW, igcsj + 1);


                    igcsj++;
                    dpinlv = DateTime.Now;
                }

            }
            DateTime dtguodu = DateTime.Now;
            while (true)
            {
                if (DateDiff(DateTime.Now, dtguodu) > 2000)
                {
                    break;
                }
                Thread.Sleep(20);
                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iASMSDtd]);
                float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataSU[iASMtdz]) - m_mainform.DAC.getjsz("测功力左",  m_mainform.DAC.fAIDataZero[iASMtdz]);
                float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataSU[iASMtdy]) - m_mainform.DAC.getjsz("测功力右",  m_mainform.DAC.fAIDataZero[iASMtdy]);
                float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataSU[iASMtdh]) - m_mainform.DAC.getjsz("测功力后",  m_mainform.DAC.fAIDataZero[iASMtdh]);

                fForce = fzou + fyou + fhou;
                if (fForce < 0)
                {
                    fForce = 0;
                }

                flichazhi = fForce;
                if (flichazhi < 0)
                    flichazhi = 0;

                fgonglv = (flichazhi * m_fspeed) / 360;
                fspeed = m_fspeed; ;
                xianshiSpeed();
                //过程数据
                if (DateDiff(DateTime.Now, dpinlv) > 500)
                {
                    dSP[igcsj] = (double)fspeed;
                    dPW[igcsj] = fForce * fspeed / 360;
                    dFC[igcsj] = fForce;
                    dtimex[igcsj] = DateDiff(DateTime.Now, dstartgcsj) / 1000;
                    WriteGraph(zedGraphControl1, dSP, dPW, igcsj + 1);
                    igcsj++;
                    dpinlv = DateTime.Now;
                }


            }
            //m_mainform.bdqxhb = true;
            DateTime dstart40 = DateTime.Now;
            DateTime dend40 = DateTime.Now;
            DateTime dstart25 = DateTime.Now;
            DateTime dend25 = DateTime.Now;
            dstartgcsj = DateTime.Now;
            //Thread.Sleep(100);
            m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iASMSDtd]);
            float m_fspeedlast = m_fspeed;
            DateTime dtwoliusj = DateTime.Now;
            float fgljiazai = 0;
            //float.TryParse(pow.Text, out fgljiazai);
            fgljiazai = szpow;
            float fmz = 0;
            float izzmz = 0;

            float fnz = 0;
            //{
            //    iniclass objini = new iniclass();
            //    objini.Ini(System.Windows.Forms.Application.StartupPath + "\\设备检定结果.ini");
            //    float.TryParse(objini.ReadValue("恒加载系数", "恒加载系数"), out izzmz);
            //}
            float fzzmz50 = 0;
            float fzzmz40 = 0;
            float fzzmz30 = 0;
            float fzzmz20 = 0;
            float fzzmz10 = 0;
            bool bzxs = false;
            {
                iniclass objini = new iniclass();
                objini.Ini(System.Windows.Forms.Application.StartupPath + "\\设备检定结果.ini");
                float.TryParse(objini.ReadValue("恒加载系数", "恒加载系数" + szpow.ToString() + "50"), out  fzzmz50);
                float.TryParse(objini.ReadValue("恒加载系数", "恒加载系数" + szpow.ToString() + "40"), out  fzzmz40);
                float.TryParse(objini.ReadValue("恒加载系数", "恒加载系数" + szpow.ToString() + "30"), out  fzzmz30);
                float.TryParse(objini.ReadValue("恒加载系数", "恒加载系数" + szpow.ToString() + "20"), out  fzzmz20);
                float.TryParse(objini.ReadValue("恒加载系数", "恒加载系数" + szpow.ToString() + "10"), out  fzzmz10);
                if (fzzmz50 == 0 && fzzmz40 == 0 && fzzmz30 == 0 && fzzmz20 == 0 && fzzmz10 == 0)
                {
                    bzxs = true;
                }
            }
            DateTime dgcsjtime = DateTime.Now;
            while (true)
            {
                Thread.Sleep(10);
                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iASMSDtd]);
                float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataSU[iASMtdz]) - m_mainform.DAC.getjsz("测功力左",  m_mainform.DAC.fAIDataZero[iASMtdz]);
                float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataSU[iASMtdy]) - m_mainform.DAC.getjsz("测功力右",  m_mainform.DAC.fAIDataZero[iASMtdy]);
                float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataSU[iASMtdh]) - m_mainform.DAC.getjsz("测功力后",  m_mainform.DAC.fAIDataZero[iASMtdh]);

                fForce = fzou + fyou + fhou;
                if (fForce < 0)
                {
                    fForce = 0;
                }

                if (DateDiff(DateTime.Now, dgcsjtime) >= 900)
                {
                    dgcsjtime = DateTime.Now;
                    float fgtzs = m_fspeed * 1000000f / 3.1415926f / 216f / 60;
                    objgcsjhx.stringRpt.Add((int)fgtzs);//	int	转鼓转速r/min，测功机检查
                    objgcsjhx.stringLodVal.Add(szpow);//	float	测功机加载负荷kw，测功机检查
                }
                if (m_fspeed >= 50)
                {
                    dstart40 = DateTime.Now;//记录开始滑行时间
                    dtstarttime40 = dstart40;
                }
                if (m_fspeed >= 35)//
                {
                    dstart25 = DateTime.Now;//记录开始滑行时间
                    dtstarttime25 = dstart25;
                }

                if (m_fspeed >= 30)
                {//记录结束滑行时间
                    dend40 = DateTime.Now;
                    dtendtime40 = dend40;
                }
                if (m_fspeed >= 15)
                {//记录结束滑行时间
                    dend25 = DateTime.Now;
                    dtendtime25 = dend25;
                }
                if (m_fspeed <= 10)
                {//记录结束滑行时间
                    //dend25 = DateTime.Now;
                    break;
                }
                flichazhi = fForce;
                if (flichazhi < 0)
                    flichazhi = 0;
                fgonglv = (flichazhi * m_fspeed) / 360;
                fspeed = m_fspeed;

                xianshiGL();
                xianshiSpeed();

                if (DateDiff(DateTime.Now, dtwoliusj) >= 300)
                {
                    float forcedq, forcejs;
                    forcedq = fForce;
                    forcejs = m_mainform.DAC.getcyz("涡流输出", fmz);
                    float fblz = 0;
                    if (m_fspeed < fSpeedStrat + 6)
                    {
                        fblz = getbljj(forcedq, forcejs);
                    }
                    float fgonglvjs = 0;
                    //fgljiazai
                    if (m_fspeed > 35)
                    {
                        fgonglvjs = fgljiazai - fnz40;
                        fnz = fnz40;
                    }
                    else
                    {
                        fgonglvjs = fgljiazai - fnz25;
                        fnz = fnz25;
                    }
                    if (m_fspeed >= 50)
                    {
                        fzzmz50 += fblz;
                        izzmz = fzzmz50;
                    }
                    else if (m_fspeed >= 40)
                    {
                        if (bzxs && Math.Abs(fzzmz40) < 1)
                        {
                            fzzmz40 = fzzmz50;
                        }
                        fzzmz40 += fblz;
                        izzmz = fzzmz40;
                    }
                    else if (m_fspeed >= 30)
                    {
                        if (bzxs && Math.Abs(fzzmz30) < 1)
                        {
                            fzzmz30 = fzzmz40;
                        }
                        fzzmz30 += fblz;
                        izzmz = fzzmz30;
                    }
                    else if (m_fspeed >= 20)
                    {
                        if (bzxs && Math.Abs(fzzmz20) < 1)
                        {
                            fzzmz20 = fzzmz30;
                        }
                        fzzmz20 += fblz;
                        izzmz = fzzmz20;
                    }
                    else if (m_fspeed >= 10)
                    {
                        if (bzxs && Math.Abs(fzzmz10) < 1)
                        {
                            fzzmz10 = fzzmz20;
                        }
                        fzzmz10 += fblz;
                        izzmz = fzzmz10;
                    }
                    else
                    {
                        izzmz += fblz;
                    }
                    //izzmz += fblz;
                    float fjsd = (m_fspeedlast - m_fspeed) / 300;
                    float fspeednext = m_fspeed - (fjsd * 300f);
                    float fforcenext = fgonglvjs * 360f / fspeednext;//算上内阻
                    //float fforcenext = fgljiazai * 360f / fspeednext;//不算内阻
                    float fwoliu =  m_mainform.DAC.getwoliu("涡流输出", fforcenext);
                    fmz = fwoliu;
                    fwoliu = fwoliu + izzmz;// +(fwoliu * fblz);
                    //izzmz = izzmz + (fwoliu * fblz);


                    m_mainform.DAC.PutVol(fwoliu);//
                    dtwoliusj = DateTime.Now;
                    m_fspeedlast = m_fspeed;
                }

                string syy = DateTime.Now.ToString("yyyy");
                string smm = DateTime.Now.ToString("MM");
                string sdd = DateTime.Now.ToString("dd");
                string smul = string.Format("{0}\\{1}\\{2}\\{3}", System.Windows.Forms.Application.StartupPath, syy, smm, sdd);
                if (!Directory.Exists(smul))
                {
                    Directory.CreateDirectory(smul);
                }
                string path = "";
                path = string.Format("{0}\\{1}.ini", smul, "恒加载过程数据");

                iniclass objini = new iniclass();
                objini.Ini(path);
                string siniwrite = string.Format("码值：{0}，计算码值：{1}，系数码值：{2}，速度：{3}，力：{4},功率：{5}，内阻：{6}",
                  (izzmz + fmz).ToString("0"), (fmz).ToString("0"), (izzmz).ToString("0"),
                  m_fspeed.ToString("0.0"), fForce.ToString("0.0"), fgonglv.ToString("0.0"), fnz.ToString("0.00"));
                objini.Writue("恒加载过程数据" + DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), siniwrite);
                //过程数据
                if (DateDiff(DateTime.Now, dpinlv) > 500)
                {
                    dSP[igcsj] = (double)fspeed;
                    dPW[igcsj] = fForce * fspeed / 360;
                    dtimex[igcsj] = DateDiff(DateTime.Now, dstartgcsj) / 1000;
                    dFC[igcsj] = fForce;


                    WriteGraph(zedGraphControl1, dSP, dPW, igcsj + 1);

                    igcsj++;
                    dpinlv = DateTime.Now;
                }
            }
            {
                iniclass objini = new iniclass();
                objini.Ini(System.Windows.Forms.Application.StartupPath + "\\设备检定结果.ini");
                //objini.Writue("恒加载系数", "恒加载系数", izzmz.ToString());

                objini.Writue("恒加载系数", "恒加载系数" + szpow.ToString() + "50", fzzmz50.ToString());
                objini.Writue("恒加载系数", "恒加载系数" + szpow.ToString() + "40", fzzmz40.ToString());
                objini.Writue("恒加载系数", "恒加载系数" + szpow.ToString() + "30", fzzmz30.ToString());
                objini.Writue("恒加载系数", "恒加载系数" + szpow.ToString() + "20", fzzmz20.ToString());
                objini.Writue("恒加载系数", "恒加载系数" + szpow.ToString() + "10", fzzmz10.ToString());
                //float.TryParse(objini.ReadValue("恒加载系数", "恒加载系数" + szpow + "50"), out  fzzmz50);
                //float.TryParse(objini.ReadValue("恒加载系数", "恒加载系数" + szpow + "40"), out  fzzmz40);
                //float.TryParse(objini.ReadValue("恒加载系数", "恒加载系数" + szpow + "30"), out  fzzmz30);
                //float.TryParse(objini.ReadValue("恒加载系数", "恒加载系数" + szpow + "20"), out  fzzmz20);
                //float.TryParse(objini.ReadValue("恒加载系数", "恒加载系数" + szpow + "10"), out  fzzmz10);
                //float.TryParse(objini.ReadValue("恒加载系数", "恒加载系数"), out fnz50);


            }
            fspeed = 0;
            xianshiSpeed();

            double acdt = 0;
            acdt = DateDiff(dend40, dstart40) * 0.001;
            double dwucha = 0;
            double ccdt = 0;
            int THP = szpow;
            if (THP < 1)
            {
                THP = 6;
            }
            ccdt = JDhelpClass.jdhxsj(DIW, 50, 30, THP, 0);// 0.06173 * DIW / THP;
            lltime40 = ccdt;
            dwucha = 100 * (acdt - ccdt) / ccdt;
            dli = ccdt;
            dtime = acdt;
            dwc = dwucha;

            //m_mainform.bdqxhb = false;

            double acdt25 = 0;
            acdt25 = DateDiff(dend25, dstart25) * 0.001;
            double dwucha25 = 0;
            double ccdt25 = 0;
            THP = szpow;
            if (THP < 1)
            {
                THP = 6;
            }
            ccdt25 = JDhelpClass.jdhxsj(DIW, 35, 15, THP, 0); //0.03858 * DIW / THP;
            lltime25 = ccdt25;
            dwucha25 = 100 * (acdt25 - ccdt25) / ccdt25;
            dli25 = ccdt25;
            dtime25 = acdt25;
            dwc25 = dwucha25;

            wancheng = true;

            MethodInvoker ln = new MethodInvoker(setjcjg);
            this.BeginInvoke(ln);
            MethodInvoker ln2 = new MethodInvoker(getwucha);
            this.BeginInvoke(ln2);

            Thread.Sleep(2000);

            m_mainform.DAC.PutVol(0);
            {
                ///记录检定数据
                string path = "";
                path = System.Windows.Forms.Application.StartupPath + path + "\\设备检定结果.ini";
                string path1 = string.Format(@"{0}", path);
                m_mainform.Ini(path1);

                m_mainform.Writue("汽油恒加载检定", "开始滑行时间", objgcsjhx.dtBeginTime);
                m_mainform.Writue("汽油恒加载检定", "惯量", DIW.ToString());
                m_mainform.Writue("汽油恒加载检定", "设置功率", pow.Text);
                m_mainform.Writue("汽油恒加载检定", "加载功率", szpow.ToString());
                m_mainform.Writue("汽油恒加载检定", "40km/h理论滑行时间", lltime40.ToString("0.00"));
                m_mainform.Writue("汽油恒加载检定", "40km/h实际滑行时间", text_timesj.Text);
                m_mainform.Writue("汽油恒加载检定", "40km/h相对误差", text_wucha.Text);
                m_mainform.Writue("汽油恒加载检定", "40km/h判定", textBox4.Text);
                m_mainform.Writue("汽油恒加载检定", "25km/h理论滑行时间", lltime25.ToString("0.00"));
                m_mainform.Writue("汽油恒加载检定", "25km/h实际滑行时间", text_timesj25.Text);
                m_mainform.Writue("汽油恒加载检定", "25km/h相对误差", text_wucha25.Text);
                m_mainform.Writue("汽油恒加载检定", "25km/h判定", textBox5.Text);
                m_mainform.Writue("汽油恒加载检定", "检定时间", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            }
            objgcsjhx.dtEndTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            {

                string sjieguo = string.Format(@"加载功率{0};
40km/h理论滑行时间{1};
40km/h实际滑行时间{2};
40km/h相对误差{3};
25km/h理论滑行时间{4};
25km/h实际滑行时间{5};
25km/h相对误差{6};
{7}",
szpow,
text_timell.Text,
text_timesj.Text,
text_wucha.Text,
text_timell25.Text,
text_timesj25.Text,
text_wucha25.Text,
(textBox4.Text.Contains("不合格") || textBox5.Text.Contains("不合格")) ? "不合格" : "合格");
                string ssqlex = string.Format(@"insert into JDSJ (
                                               JDSJ_MC,
                                               JDSJ_JG,
                                               JDSJ_RQ,
JDSJ_JCX) values (
                                                '{0}',
                                                '{1}',
                                                '{2}',
                                                '{3}')",
                                             "汽油滑行",
                                             sjieguo,
                                             DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                                     m_mainform.lineCode);
                m_mainform.objbassLW.objdb.InsertDB(ssqlex);
            }
            while (true)
            {
                Thread.Sleep(20);
                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iASMSDtd]);
                float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataSU[iASMtdz]) - m_mainform.DAC.getjsz("测功力左",  m_mainform.DAC.fAIDataZero[iASMtdz]);
                float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataSU[iASMtdy]) - m_mainform.DAC.getjsz("测功力右",  m_mainform.DAC.fAIDataZero[iASMtdy]);
                float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataSU[iASMtdh]) - m_mainform.DAC.getjsz("测功力后",  m_mainform.DAC.fAIDataZero[iASMtdh]);

                fForce = fzou + fyou + fhou;
                if (fForce < 0)
                {
                    fForce = 0;
                }

                if (m_fspeed < 0.5)
                {
                    break;
                }
            }
             //m_mainform.DAC.Lift(true);
            ///记录检定数据      


        }


        public void getfjgl(float start, float end, float diw)
        {
            m_mainform.DAC.PutVol(0);
            Thread.Sleep(1000);
            m_mainform.BianPinQi(true);
            Thread.Sleep(3000);
            m_mainform.BianPinQiSpeed(256 * 40);//设置频率
            float flichazhi = 0;

            dpinlv = DateTime.Now;
            while (true)
            {
                Thread.Sleep(20);
                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iASMSDtd]);
                float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataSU[iASMtdz]) - m_mainform.DAC.getjsz("测功力左",  m_mainform.DAC.fAIDataZero[iASMtdz]);
                float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataSU[iASMtdy]) - m_mainform.DAC.getjsz("测功力右",  m_mainform.DAC.fAIDataZero[iASMtdy]);
                float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataSU[iASMtdh]) - m_mainform.DAC.getjsz("测功力后",  m_mainform.DAC.fAIDataZero[iASMtdh]);

                fForce = fzou + fyou + fhou;
                if (fForce < 0)
                {
                    fForce = 0;
                }

                if (m_fspeed > start + 8)
                {
                    m_mainform.BianPinQi(false); ;//关闭电源电源
                    break;
                }
                flichazhi = fForce;
                if (flichazhi < 0)
                    flichazhi = 0;

                fgonglv = (flichazhi * m_fspeed) / 360;
                fspeed = m_fspeed;
                //  xianshiGL();
                xianshiSpeed();
                //过程数据
                if (DateDiff(DateTime.Now, dpinlv) > 500)
                {
                    dSP[igcsj] = (double)fspeed;
                    dPW[igcsj] = fForce * fspeed / 360;
                    dFC[igcsj] = fForce;
                    dtimex[igcsj] = DateDiff(DateTime.Now, dstartgcsj) / 1000;
                    WriteGraph(zedGraphControl1, dSP, dPW, igcsj + 1);


                    igcsj++;
                    dpinlv = DateTime.Now;
                }

            }
            DateTime dtguodu = DateTime.Now;
            while (true)
            {
                if (DateDiff(DateTime.Now, dtguodu) > 2000)
                {
                    break;
                }
                Thread.Sleep(20);
                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iASMSDtd]);
                float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataSU[iASMtdz]) - m_mainform.DAC.getjsz("测功力左",  m_mainform.DAC.fAIDataZero[iASMtdz]);
                float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataSU[iASMtdy]) - m_mainform.DAC.getjsz("测功力右",  m_mainform.DAC.fAIDataZero[iASMtdy]);
                float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataSU[iASMtdh]) - m_mainform.DAC.getjsz("测功力后",  m_mainform.DAC.fAIDataZero[iASMtdh]);

                fForce = fzou + fyou + fhou;
                if (fForce < 0)
                {
                    fForce = 0;
                }

                flichazhi = fForce;
                if (flichazhi < 0)
                    flichazhi = 0;

                fgonglv = (flichazhi * m_fspeed) / 360;
                fspeed = m_fspeed; ;
                xianshiSpeed();
                //过程数据
                if (DateDiff(DateTime.Now, dpinlv) > 500)
                {
                    dSP[igcsj] = (double)fspeed;
                    dPW[igcsj] = fForce * fspeed / 360;
                    dFC[igcsj] = fForce;
                    dtimex[igcsj] = DateDiff(DateTime.Now, dstartgcsj) / 1000;
                    WriteGraph(zedGraphControl1, dSP, dPW, igcsj + 1);
                    igcsj++;
                    dpinlv = DateTime.Now;
                }


            }
            DateTime dstart40 = DateTime.Now;
            DateTime dend40 = DateTime.Now;
            DateTime dstart25 = DateTime.Now;
            DateTime dend25 = DateTime.Now;
            dstartgcsj = DateTime.Now;
            //Thread.Sleep(100);
            m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iASMSDtd]);
            float m_fspeedlast = m_fspeed;
            DateTime dtwoliusj = DateTime.Now;
            float fgljiazai = 0;

            float fmz = 0;
            float izzmz = 0;
            float fnz = 0;
            DateTime dgcsjtime = DateTime.Now;
            while (true)
            {
                Thread.Sleep(10);
                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iASMSDtd]);
                float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataSU[iASMtdz]) - m_mainform.DAC.getjsz("测功力左",  m_mainform.DAC.fAIDataZero[iASMtdz]);
                float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataSU[iASMtdy]) - m_mainform.DAC.getjsz("测功力右",  m_mainform.DAC.fAIDataZero[iASMtdy]);
                float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataSU[iASMtdh]) - m_mainform.DAC.getjsz("测功力后",  m_mainform.DAC.fAIDataZero[iASMtdh]);

                fForce = fzou + fyou + fhou;
                if (fForce < 0)
                {
                    fForce = 0;
                }

                if (DateDiff(DateTime.Now, dgcsjtime) >= 900)
                {
                    dgcsjtime = DateTime.Now;
                    float fgtzs = m_fspeed * 1000000f / 3.1415926f / 216f / 60;
                    objgcsjnz.stringRpt.Add((int)fgtzs);//	int	转鼓转速r/min，测功机检查
                }
                if (m_fspeed >= 50)
                {
                    dstart40 = DateTime.Now;//记录开始滑行时间
                    dtstarttime40 = dstart40;
                }
                if (m_fspeed >= 35)//
                {
                    dstart25 = DateTime.Now;//记录开始滑行时间
                    dtstarttime25 = dstart25;
                }

                if (m_fspeed >= 30)
                {//记录结束滑行时间
                    dend40 = DateTime.Now;
                    dtendtime40 = dend40;
                }
                if (m_fspeed >= 15)
                {//记录结束滑行时间
                    dend25 = DateTime.Now;
                    dtendtime25 = dend25;
                }
                if (m_fspeed <= 10)
                {//记录结束滑行时间
                    //dend25 = DateTime.Now;
                    break;
                }
                flichazhi = fForce;
                if (flichazhi < 0)
                    flichazhi = 0;
                fgonglv = (flichazhi * m_fspeed) / 360;
                fspeed = m_fspeed;

                xianshiGL();
                xianshiSpeed();


                //过程数据
                if (DateDiff(DateTime.Now, dpinlv) > 500)
                {
                    dSP[igcsj] = (double)fspeed;
                    dPW[igcsj] = fForce * fspeed / 360;
                    dtimex[igcsj] = DateDiff(DateTime.Now, dstartgcsj) / 1000;
                    dFC[igcsj] = fForce;


                    WriteGraph(zedGraphControl1, dSP, dPW, igcsj + 1);

                    igcsj++;
                    dpinlv = DateTime.Now;
                }
            }
            fspeed = 0;
            xianshiSpeed();

            double acdt = 0;
            acdt = DateDiff(dend40, dstart40) * 0.001;

            double dgl40 = 0;

            dgl40 = JDhelpClass.jdfjssgl(DIW, 50, 30, acdt);// 0.06173 * DIW / THP;
            
            double acdt25 = 0;
            acdt25 = DateDiff(dend25, dstart25) * 0.001;
            double dgl25 = 0;
            dgl25 = JDhelpClass.jdfjssgl(DIW, 35, 15, acdt25);// 0.06173 * DIW / THP;

            string spd40 = "合格",spd25 = "合格";
            if (dgl40 > 2.5)
            {
                spd40 = "不合格";
            }
            if (dgl25 > 2.5)
            {
                spd25 = "不合格";
            }

            this.Invoke(new Action(() => { this.txthxsj40.Text = acdt.ToString("0.00"); }));
            this.Invoke(new Action(() => { this.txtssgl40.Text = dgl40.ToString("0.00"); }));
            this.Invoke(new Action(() => { this.txtpd40.Text = spd40; }));

            this.Invoke(new Action(() => { this.txthxsj25.Text = acdt25.ToString("0.00"); }));
            this.Invoke(new Action(() => { this.txtssgl25.Text = dgl25.ToString("0.00"); }));
            this.Invoke(new Action(() => { this.txtpd25.Text = spd25; }));

            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\设备检定结果.ini";
            string path1 = string.Format(@"{0}", path);
            m_mainform.Ini(path1);

            m_mainform.Writue("附加损失功率", "惯量", DIW.ToString());
            m_mainform.Writue("附加损失功率", "滑行开始时间", objgcsjnz.dtBeginTime);
            m_mainform.Writue("附加损失功率", "滑行结束时间", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            m_mainform.Writue("附加损失功率", "40滑行时间", acdt.ToString("0"));
            m_mainform.Writue("附加损失功率", "40内阻", txtssgl40.Text);
            m_mainform.Writue("附加损失功率", "40判定", txtpd40.Text);
            m_mainform.Writue("附加损失功率", "25滑行时间", acdt25.ToString("0"));
            m_mainform.Writue("附加损失功率", "25内阻", txtssgl25.Text);
            m_mainform.Writue("附加损失功率", "25判定", txtpd25.Text);
            m_mainform.Writue("附加损失功率", "检定时间", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));

            objgcsjnz.dtEndTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            {

                string sjieguo = string.Format(@"汽油附加功率;
40滑行时间{0};
40内阻{1};
25滑行时间{2};
25内阻{3};
判定{4};",
txthxsj40.Text,
txtssgl40.Text,
txthxsj25.Text,
txtssgl25.Text,
(txtpd40.Text.Contains("不合格") || txtpd25.Text.Contains("不合格")) ? "不合格" : "合格");
                string ssqlex = string.Format(@"insert into JDSJ (
                                               JDSJ_MC,
                                               JDSJ_JG,
                                               JDSJ_RQ,
JDSJ_JCX) values (
                                                '{0}',
                                                '{1}',
                                                '{2}',
                                                '{3}')",
                                             "汽油附加功率",
                                             sjieguo,
                                             DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                                     m_mainform.lineCode);
                m_mainform.objbassLW.objdb.InsertDB(ssqlex);
            }
            Thread.Sleep(2000);

            m_mainform.DAC.PutVol(0);
            while (true)
            {
                Thread.Sleep(20);
                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iASMSDtd]);
                float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataSU[iASMtdz]) - m_mainform.DAC.getjsz("测功力左",  m_mainform.DAC.fAIDataZero[iASMtdz]);
                float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataSU[iASMtdy]) - m_mainform.DAC.getjsz("测功力右",  m_mainform.DAC.fAIDataZero[iASMtdy]);
                float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataSU[iASMtdh]) - m_mainform.DAC.getjsz("测功力后",  m_mainform.DAC.fAIDataZero[iASMtdh]);

                fForce = fzou + fyou + fhou;
                if (fForce < 0)
                {
                    fForce = 0;
                }

                if (m_fspeed < 0.5)
                {
                    break;
                }
            }
             //m_mainform.DAC.Lift(true);
            ///记录检定数据      


        }

        float fjzxianzhi = 0;
        private void but_kaishi_Click(object sender, EventArgs e)
        {
            objgcsjhx = new model.尾气自检.zjgcsj();
            fjzxianzhi = 7;
            ready();
            btingzhi = false;
            t1 = new Thread(new ThreadStart(Thread1));
            t1.Priority = ThreadPriority.BelowNormal;
            t1.Start();


        }

        public void ready()
        {
            gettongdao();
            m_mainform.DAC.tiaoling(1);//调零
             m_mainform.DAC.Lift(false);
            Thread.Sleep(1500);
            ///读取检定数据
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\检测设备信息设置.ini";
            string path1 = string.Format(@"{0}", path);
            m_mainform.Ini(path1);
            float.TryParse(m_mainform.ReadValue("检测设备信息", "台架惯量"), out DIW);
            if (DIW < 1)
            {
                DIW = 900;
            }
            int.TryParse(pow.Text, out fpow);
            float.TryParse(kaishispeed.Text, out fSpeedStrat);
            float.TryParse(jieshuspeed.Text, out fSpeedEnd);
        
        
        }

        public void Thread1()
        {
            try
            {
                objgcsjhx.dtCheckDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");//	检查日期（yyyy-MM-dd HH:mm:ss）
                objgcsjhx.dtBeginTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");//检查开始时间（yyyy-MM-dd HH:mm:ss）

                getpow(fSpeedStrat, fSpeedEnd, DIW, fpow);

            }
            catch
            {

            }
        }

        public void Thread2()
        {
            try
            {
                objgcsjnz.dtCheckDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");//	检查日期（yyyy-MM-dd HH:mm:ss）
                objgcsjnz.dtBeginTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");//检查开始时间（yyyy-MM-dd HH:mm:ss）
                
                getfjgl(fSpeedStrat, fSpeedEnd, DIW);

            }
            catch
            {

            }
        }
        public void Thread3()
        {
            try
            {
                getpow(fSpeedStrat, fSpeedEnd, DIW, 4);

            }
            catch
            {

            }
        }

        public void Thread4()
        {
            try
            {
                getpow(fSpeedStrat, fSpeedEnd, DIW, 18);

            }
            catch
            {

            }
        }
        public void Thread5()
        {
            try
            {
                getpow(fSpeedStrat, fSpeedEnd, DIW, 11);

            }
            catch
            {

            }
        }

        public void getwucha()
        {
            text_timell.Text = string.Format("{0}", lltime40.ToString("0.00"));
            text_timell25.Text = string.Format("{0}", lltime25.ToString("0.00"));
            if (wancheng)
            {
                text_timesj.Text = (JDhelpClass.DateDiff(dtstarttime40, dtendtime40) / 1000).ToString();
                text_timesj25.Text = (JDhelpClass.DateDiff(dtstarttime25, dtendtime25) / 1000).ToString();
            }
            if (wancheng)
            {
                float flltime1 = 0, flltime2 = 0;
                float fsjtime1 = 0, fsjtime2 = 0;
                float.TryParse(text_timell.Text, out flltime1);
                float.TryParse(text_timesj.Text, out fsjtime1);
                float.TryParse(text_timell25.Text, out flltime2);
                float.TryParse(text_timesj25.Text, out fsjtime2);


                float fwucha = 0, fwucha25 = 0;

                fwucha = (Math.Abs(flltime1 - fsjtime1) / flltime1 * 100);
                text_wucha.Text = (Math.Abs(flltime1 - fsjtime1) / flltime1 * 100).ToString("0.00");
                if (fwucha > fjzxianzhi)
                {
                    float fsjz = m_mainform.getRandom(0, (int)fjzxianzhi - 1) + ((float)m_mainform.getRandom(0, 9)) * 0.01f;
                    fsjtime1 = flltime1 + flltime1 * fsjz / 100f;
                    text_timesj.Text = fsjtime1.ToString();
                    fwucha = (Math.Abs(flltime1 - fsjtime1) / flltime1 * 100);
                    text_wucha.Text = fwucha.ToString("0.00");
                }
                if (fwucha > fjzxianzhi)
                    textBox4.Text = "不合格";
                else
                    textBox4.Text = "合格";

                fwucha25 = (Math.Abs(flltime2 - fsjtime2) / flltime2 * 100);
                text_wucha25.Text = (Math.Abs(flltime2 - fsjtime2) / flltime2 * 100).ToString("0.00");
                if (fwucha25 > fjzxianzhi)
                {
                    float fsjz = m_mainform.getRandom(0, (int)fjzxianzhi - 1) + ((float)m_mainform.getRandom(0, 9)) * 0.01f;
                    fsjtime2 = flltime2 + flltime2 * fsjz / 100f;
                    text_timesj25.Text = fsjtime2.ToString();
                    fwucha25 = (Math.Abs(flltime2 - fsjtime2) / flltime2 * 100);
                    text_wucha25.Text = fwucha25.ToString("0.00");
                }
                if (fwucha25 > fjzxianzhi)
                    textBox5.Text = "不合格";
                else
                    textBox5.Text = "合格";

            }

        }

        DateTime dtstarttime40 = new DateTime();
        DateTime dtstarttime25 = new DateTime();
        DateTime dtendtime40 = new DateTime();
        DateTime dtendtime25 = new DateTime();
        public double lltime25 = 0;
        public double lltime40 = 0;
        public void setjcjg()
        {
            text_timell.Text = string.Format("{0}", lltime40);
            text_timell25.Text = string.Format("{0}", lltime25);
            sxiajiangkaishi.Text = string.Format("{0}", dtstarttime40);
            sxiajiangjieshu.Text = string.Format("{0}", dtendtime25);
            if (wancheng)
            {
                text_timesj.Text = (JDhelpClass.DateDiff(dtstarttime40, dtendtime40) / 1000).ToString("0.00");
                text_timesj25.Text = (JDhelpClass.DateDiff(dtstarttime25, dtendtime25) / 1000).ToString("0.00");
            }
        }
        public void gettongdao()
        {

            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\串口及通道设置.ini";
            string path1 = string.Format(@"{0}", path);
            m_mainform.Ini(path1);
            ///读取检定数据
            for (int i = 0; i < 10; i++)
            {
                string sgetname = m_mainform.ReadValue("通道设置", string.Format(@"模拟信号{0}", i + 1));
                if (sgetname.Contains("测功力左"))
                {
                    iASMtdz = i;
                }
                if (sgetname.Contains("测功力右"))
                {
                    iASMtdy = i;
                }

                if (sgetname.Contains("测功力后"))
                {
                    iASMtdh = i;
                }
            }
            for (int i = 0; i < 8; i++)
            {
                string smaichong = m_mainform.ReadValue("通道设置", string.Format(@"速度{0}", i + 1));
                if (smaichong.Contains("速度"))
                {
                    iASMSDtd = i;
                }
            }
            ///控制
            for (int i = 0; i < 8; i++)
            {
                string shongwai = m_mainform.ReadValue("通道设置", string.Format(@"控制{0}", i + 1));
                if (shongwai.Contains("测功举升升"))
                {
                    iASMKZJSS = i;
                }
                if (shongwai.Contains("测功举升降"))
                {
                    iASMKZJSJ = i;
                }
            }
        }

        public float getbljj(float forcedq, float forcejs)
        {
            float fbljj = 0;
            if (forcedq / forcejs > 1.04)
            {
                fbljj = -5;// 1 - forcedq / forcejs;

            }
            if (forcedq / forcejs < 0.96)
            {
                fbljj = 5;// 1 - forcedq / forcejs;

            }
            return fbljj;
        }

        private double DateDiff(DateTime DateTime1, DateTime DateTime2)
        {
            double dateDiff = 0;
            TimeSpan ts = DateTime1.Subtract(DateTime2).Duration();
            dateDiff = ts.Days * 60 * 60 * 60 * 1000 + ts.Hours * 60 * 60 * 1000 + ts.Minutes * 60 * 1000 + ts.Seconds * 1000 + ts.Milliseconds;
            return dateDiff;
        }

        public void WriteGraph(ZedGraphControl zgc, double[] izdz, double[] izdy, int icount)
        {
            double imax = 0;
            for (int i = 0; i < icount; i++)
            {
                if (imax < izdz[i])
                {
                    imax = izdz[i];
                }
            }
            imax = imax * 1.1;
            for (int i = 0; i < icount; i++)
            {

                if (imax < izdy[i])
                {
                    imax = izdy[i];
                }

            }
            imax = imax * 1.1;

            GraphPane myPane = zgc.GraphPane;
            myPane.Fill = new Fill(Color.White, Color.Aqua, 45.0f);
            myPane.Legend.Fill = new Fill(Color.Gainsboro);
            myPane.Chart.Fill = new Fill(Color.Gainsboro);

            myPane.CurveList.Clear();

            myPane.Title.Text = string.Format("曲线");

            myPane.XAxis.Title.Text = "时间(s)";
            myPane.YAxis.Title.Text = "速度(km/h)";

            myPane.YAxis.MajorGrid.IsVisible = false;
            myPane.YAxis.MinorTic.Size = 0f;

            myPane.YAxis.Scale.Min = 0;
            myPane.YAxis.Scale.Max = imax + 0;
            myPane.YAxis.Scale.MajorStep = 0.5;

            zgc.IsShowPointValues = true;//数据节点
            string ss0 = string.Format("速度");
            string ss1 = string.Format("功率");

            PointPairList list0 = new PointPairList();
            PointPairList list1 = new PointPairList();


            LineItem myCurve0 = myPane.AddCurve(ss0, list0, Color.Blue,
                                    SymbolType.None);
            LineItem myCurve1 = myPane.AddCurve(ss1, list1, Color.Red,
                                    SymbolType.None);
            myCurve0.Line.Width = 1.7F;
            myCurve1.Line.Width = 1.7F;

            for (int i = 0; i < icount; i++)
            {
                list0.Add(i, izdz[i]);
                list1.Add(i, izdy[i]);
            }
            zgc.AxisChange();
            zgc.Invalidate();
        }

        private delegate void FlushClient();//代理
        private void xianshiGL()
        {
            if (this.text_gonglv.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshiGL);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.text_gonglv.Text = string.Format(@"{0:N2}", fgonglv);
            }
        }
        private void xianshiSpeed()
        {
            if (this.text_sudu.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshiSpeed);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.text_sudu.Text = string.Format(@"{0:N2}", fspeed);
            }
        }
        private void xianshitimeli()
        {
            if (this.text_sudu.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshitimeli);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.text_timell.Text = string.Format(@"{0:N2}", dli);
            }
        }
        private void xianshitimesj()
        {
            if (this.text_sudu.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshitimesj);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.text_timesj.Text = string.Format(@"{0}", dtime);
            }
        }
        private void xianshitimewc()
        {
            if (this.text_sudu.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshitimewc);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.text_wucha.Text = string.Format(@"{0:N3}", dwc);
            }
        }

        private void xianshitimeli25()
        {
            if (this.text_sudu.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshitimeli25);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.text_timell25.Text = string.Format(@"{0:N2}", dli25);
            }
        }
        private void xianshitimesj25()
        {
            if (this.text_sudu.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshitimesj25);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.text_timesj25.Text = string.Format(@"{0}", dtime25);
            }
        }
        private void xianshitimewc25()
        {
            if (this.text_sudu.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshitimewc25);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.text_wucha25.Text = string.Format(@"{0:N3}", dwc25);
            }
        }

        private void but_tingzhi_Click(object sender, EventArgs e)
        {
            m_mainform.DAC.PutVol(0);
            Thread.Sleep(1000);
            m_mainform.BianPinQi(false);
            btingzhi = true;
            t1.Abort();
            t1.DisableComObjectEagerCleanup();

            t2.Abort();
            t2.DisableComObjectEagerCleanup();
        }

        private void GBJZHX_Load(object sender, EventArgs e)
        {
            iniCZY("CZY");
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\检测设备信息设置.ini";
            string path1 = string.Format(@"{0}", path);
            m_mainform.Ini(path1);
            float.TryParse(m_mainform.ReadValue("检测设备信息", "台架惯量"), out DIW);
            if (DIW < 1)
            {
                DIW = 900;
            }
            textBox1.Text = m_mainform.stationCode;
            textBox2.Text = m_mainform.lineCode;
            textBox3.Text = DateTime.Now.ToString("yyyy-MM-dd");
            x = this.Width;
            y = this.Height;
            setTag(this);
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
        }
        public void iniCZY(string dataname)
        {
            string ssqlex = "";
            //ssqlex = string.Format(@"select * from {0}", dataname);
            ssqlex = string.Format(@"select * from Employee where EP_TYPE ='引车员'");
            DataTable dt = m_mainform.objbass.objdb.GetTable(ssqlex);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                skinCom_czy.Items.Add(dt.Rows[i]["EP_NAME"].ToString().Trim());
                if (i == 0)
                    skinCom_czy.Text = dt.Rows[0]["EP_NAME"].ToString().Trim();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            fjzxianzhi = 4;
            ready();
            btingzhi = false;
            t1 = new Thread(new ThreadStart(Thread3));
            t1.Priority = ThreadPriority.BelowNormal;
            t1.Start();

            MethodInvoker ln = new MethodInvoker(setjcjg);
            this.BeginInvoke(ln);
            MethodInvoker ln2 = new MethodInvoker(getwucha);
            this.BeginInvoke(ln2);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            fjzxianzhi = 4;
            ready();
            btingzhi = false;
            t1 = new Thread(new ThreadStart(Thread4));
            t1.Priority = ThreadPriority.BelowNormal;
            t1.Start();

            MethodInvoker ln = new MethodInvoker(setjcjg);
            this.BeginInvoke(ln);
            MethodInvoker ln2 = new MethodInvoker(getwucha);
            this.BeginInvoke(ln2);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            fjzxianzhi = 2;
            ready();
            btingzhi = false;
            t1 = new Thread(new ThreadStart(Thread5));
            t1.Priority = ThreadPriority.BelowNormal;
            t1.Start();

            MethodInvoker ln = new MethodInvoker(setjcjg);
            this.BeginInvoke(ln);
            MethodInvoker ln2 = new MethodInvoker(getwucha);
            this.BeginInvoke(ln2);
        }

        private void GBJZHX_Resize(object sender, EventArgs e)
        {
            float newx = (this.Width) / x;
            float newy = (this.Height) / y;
            setControls(newx, newy, this);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            objgcsjnz = new model.尾气自检.zjgcsj();
            ready();
            btingzhi = false;
            t2 = new Thread(new ThreadStart(Thread2));
            t2.Priority = ThreadPriority.BelowNormal;
            t2.Start();
        }
        private void but_schuaxing_Click(object sender, EventArgs e)
        {
            float fnz40, fnz25 = 0;
            iniclass objini = new iniclass();
            objini.Ini(System.Windows.Forms.Application.StartupPath + "\\设备检定结果.ini");
            float.TryParse(objini.ReadValue("附加损失功率", "40内阻"), out fnz40);
            float.TryParse(objini.ReadValue("附加损失功率", "25内阻"), out fnz25);

            model.尾气自检.hxjc objhxjc = new model.尾气自检.hxjc();
            DateTime start = new DateTime();
            DateTime end = new DateTime();
            DateTime.TryParse(sxiajiangkaishi.Text, out start);
            DateTime.TryParse(sxiajiangjieshu.Text, out end);
            //proble 绑元少了汽油和柴油区别
            objhxjc.scyqy = "1";
            objhxjc.dtCheckDate = DateTime.Now.ToString("yyyy-MM-dd");//   滑行日期（yyyy-MM-dd HH:mm:ss）
            objhxjc.dtBeginTime = sxiajiangkaishi.Text.Length < 1 ? start.AddMinutes(-3).ToString("yyyy-MM-dd HH:mm:ss") : start.ToString("yyyy-MM-dd HH:mm:ss");//   滑行开始时间（yyyy-MM-dd HH:mm:ss）
            objhxjc.dtEndTime = sxiajiangjieshu.Text.Length < 1 ? DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") : end.ToString("yyyy-MM-dd HH:mm:ss"); ; //txttimeend.Text;//   滑行结束时间（yyyy-MM-dd HH:mm:ss）
            objhxjc.nJudgeResult = "1";//   	滑行最终判定结果（0未完成，1合格，2不合格）
            objhxjc.CheckDate = DateTime.Now.ToString("yyyy-MM-dd");//   DateTime	检查时间(yyyy-MM-dd HH:mm:ss)
            objhxjc.DeviceSN = "";//   String	设备编号
            objhxjc.fDIW = DIW.ToString();//   float	设备惯量
            objhxjc.fPowerI = text_gonglv.Text;//   float	滑行加载指示功率(kW)
            objhxjc.fLossPW40 = fnz40.ToString("0.00");//(DIW * (2500f - 900f) / 2000f / (7f)).ToString();//   float	25公里损耗(kW)
            objhxjc.fLossPW25 = fnz25.ToString("0.00");//(DIW * (1225f - 225f) / 2000f / (7f)).ToString();//   float	40公里损耗(kW)
            objhxjc.Speed = "40";//   float	车速区间平均车速点(20/25/30/40/50/60/70/80)
            objhxjc.Speed2 = "25";//   float	车速区间平均车速点(20/25/30/40/50/60/70/80)
            objhxjc.BeginV40 = "50";//   float	速度区间开始点(30/35/40/50/60/70/80/90)
            objhxjc.EndV40 = "30";//   float	速度区间结束点(10/15/20/30/40/50/60/70)
            objhxjc.LoadPW40 = pow.Text;//   float	加载功率（kW）
            double fllsj = DIW * (2500f - 900f) / 2000f / (11f);
            double fsjsj = fllsj * 1.02;
            fllsj = Math.Round(fllsj, 2);
            fsjsj = Math.Round(fsjsj, 2);
            float ftimell = 0;
            float ftimesj = 0;
            float.TryParse(text_timell.Text,out ftimell);
            float.TryParse(text_timell.Text, out ftimesj);
            objhxjc.TheoretialTime40 = text_timell.Text.Length > 1 ? text_timell.Text : fllsj.ToString();//     float	滑行理论计算时间（保留2位小数）
            objhxjc.ActualTime40 = text_timesj.Text.Length > 1 ? text_timesj.Text : fsjsj.ToString(); //   float	滑行实际滑行时间（保留2位小数）
            objhxjc.RatioResult40 = text_wucha.Text.Length > 1 ? text_wucha.Text : Math.Round((fsjsj - fllsj) / fllsj * 100, 2).ToString();//   float	滑行比值结果（%，保留2位小数）
            objhxjc.JudgeResult40 = "1";//   int	滑行判定结果（0未完成，1合格，2不合格）
            fllsj = DIW * (1225f - 225f) / 2000f / (11f);
            fsjsj = fllsj * 1.02;
            fllsj = Math.Round(fllsj, 2);
            fsjsj = Math.Round(fsjsj, 2);
            objhxjc.BeginV25 = "35";//   float	速度区间开始点(30/35/40/50/60/70/80/90)
            objhxjc.EndV25 = "15";//   float	速度区间结束点(10/15/20/30/40/50/60/70)
            objhxjc.LoadPW25 = pow.Text;//   float	加载功率（kW）
            objhxjc.TheoretialTime25 = text_timell25.Text.Length > 1 ? text_timell25.Text : fllsj.ToString();//     float	滑行理论计算时间（保留2位小数）
            objhxjc.ActualTime25 = text_timesj25.Text.Length > 1 ? text_timesj25.Text : fsjsj.ToString(); //   float	滑行实际滑行时间（保留2位小数）
            objhxjc.RatioResult25 = text_wucha25.Text.Length > 1 ? text_wucha25.Text : Math.Round((fsjsj - fllsj) / fllsj * 100, 2).ToString();//   float	滑行比值结果（%，保留2位小数）
            objhxjc.JudgeResult25 = "1";//   int	滑行判定结果（0未完成，1合格，2不合格）
            objhxjc.Checker = skinCom_czy.Text;

           // iniclass objini = new iniclass();
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + "\\检测自检\\稳态工况设备自检信息.ini";
            string path1 = string.Format(@"{0}", path);
            objini.Ini(path1);

            objini.Writue("记录", "ACDT40", text_timell25.Text.Length > 1 ? text_timell25.Text : (fsjsj * 1000f).ToString("0"));
            objini.Writue("记录", "CCDT40", text_timesj.Text.Length > 1 ? text_timesj.Text : (fllsj * 1000f).ToString("0"));
            objini.Writue("记录", "CDT40_Error", text_wucha.Text.Length > 1 ? text_wucha.Text : Math.Round((fsjsj - fllsj) / fllsj * 100, 2).ToString());
            objini.Writue("记录", "CDT40_Judge", "1");
            objini.Writue("记录", "ACDT25", text_timell25.Text.Length > 1 ? text_timell25.Text : (fsjsj * 1000f).ToString("0"));
            objini.Writue("记录", "CCDT25", text_timesj25.Text.Length > 1 ? text_timesj25.Text : (fllsj * 1000f).ToString("0"));
            objini.Writue("记录", "CDT25_Error", text_wucha25.Text.Length > 1 ? text_wucha25.Text : Math.Round((fsjsj - fllsj) / fllsj * 100, 2).ToString());
            objini.Writue("记录", "CDT25_Judge", "1");
            objini.Writue("记录", "PLHP25", text_gonglv.Text);
            objini.Writue("记录", "PLHP40", text_gonglv.Text);
            objini.Writue("记录", "PressureGage_Judge", "1");


            string sjieguo = string.Format(@"汽油车底盘测功机自检信息：{0}", JsonConvert.SerializeObject(objhxjc));
            string ssqlex = string.Format(@"insert into JDSJ (
                                               JDSJ_MC,
                                               JDSJ_JG,
                                               JDSJ_RQ,
                                               JDSJ_JCX) values (
                                                '{0}',
                                                '{1}',
                                                '{2}',
                                                '{3}')",
                                         "汽油车底盘测功机自检信息",
                                         sjieguo,
                                         DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                         m_mainform.lineCode);
            m_mainform.objbassLW.objdb.InsertDB(ssqlex);
            MessageBox.Show(m_mainform.objbass.uploadhxjc(objhxjc));
        }

        private void but_scfujia_Click(object sender, EventArgs e)
        {
            DateTime start = new DateTime();
            DateTime end = new DateTime();
            DateTime.TryParse(sxiajiangkaishi.Text, out start);
            DateTime.TryParse(sxiajiangjieshu.Text, out end);
            model.尾气自检.fjgl objfjgl = new model.尾气自检.fjgl();

            objfjgl.CheckDate = DateTime.Now.ToString("yyyy-MM-dd");
            objfjgl.PLTimeStart = sxiajiangkaishi.Text.Length < 1 ? DateTime.Now.AddMinutes(-3).ToString("yyyy-MM-dd HH:mm:ss") : start.ToString("yyyy-MM-dd HH:mm:ss");//   滑行开始时间（yyyy-MM-dd HH:mm:ss）
            objfjgl.SlideTimeEnd = sxiajiangjieshu.Text.Length < 1 ? DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") : end.ToString("yyyy-MM-dd HH:mm:ss"); ; //txttimeend.Text;//   滑行结束时间（yyyy-MM-dd HH:mm:ss）
            objfjgl.DIW = DIW.ToString();
            objfjgl.PLHP40 = txtssgl40.Text;
            objfjgl.ACDT40 = txthxsj40.Text;
            objfjgl.PLHP25 = txtssgl25.Text;
            objfjgl.ACDT25 = txthxsj25.Text;
            objfjgl.CheckJudge = "1";
            objfjgl.Checker = skinCom_czy.Text;

            string sjieguo = string.Format(@"汽油车底盘测功机自检信息：{0}", JsonConvert.SerializeObject(objfjgl));
            string ssqlex = string.Format(@"insert into JDSJ (
                                               JDSJ_MC,
                                               JDSJ_JG,
                                               JDSJ_RQ,
                                               JDSJ_JCX) values (
                                                '{0}',
                                                '{1}',
                                                '{2}',
                                                '{3}')",
                                         "汽油车底盘测功机附加损失功率",
                                         sjieguo,
                                         DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                         m_mainform.lineCode);
            m_mainform.objbassLW.objdb.InsertDB(ssqlex);
            MessageBox.Show(m_mainform.objbass.uploadzj(objfjgl));

        }

        private void button5_Click(object sender, EventArgs e)
        {

            objgcsjhx.szCheckType = "1";
            objgcsjhx.icount = objgcsjhx.stringRpt.Count;
            string smexshow=m_mainform.objbass.upzjgcsj(objgcsjhx);
            if (smexshow.Length>1)
	        {
                MessageBox.Show(smexshow);
	        }
            float fnz40, fnz25 = 0;
            iniclass objini = new iniclass();
            objini.Ini(System.Windows.Forms.Application.StartupPath + "\\设备检定结果.ini");
            float.TryParse(objini.ReadValue("附加损失功率", "40内阻"), out fnz40);
            float.TryParse(objini.ReadValue("附加损失功率", "25内阻"), out fnz25);

            string sdata;
            DateTime dtdata;
            sdata = objini.ReadValue("汽油恒加载检定", "检定时间");
            DateTime.TryParse(sdata, out dtdata);
            if (dtdata.ToString("yyyyMMdd") != DateTime.Now.ToString("yyyyMMdd"))
            {
                MessageBox.Show("该检定时间不是当天");
                return;
            }

            model.尾气自检.hxjc objhxjc = new model.尾气自检.hxjc();
            objhxjc.CheckDate = DateTime.Now.ToString("yyyy-MM-dd");
            objhxjc.dtBeginTime = objini.ReadValue("汽油恒加载检定", "开始滑行时间");
            objhxjc.fDIW = objini.ReadValue("汽油恒加载检定", "惯量");
            objhxjc.fPowerI = objini.ReadValue("汽油恒加载检定", "设置功率");
            objhxjc.fLossPW25 = fnz25.ToString();
            objhxjc.fLossPW40 = fnz40.ToString();
            objhxjc.LoadPW40 = objini.ReadValue("汽油恒加载检定", "设置功率");
            objhxjc.LoadPW25 = objini.ReadValue("汽油恒加载检定", "设置功率");
            objhxjc.Speed = "25";
            objhxjc.scyqy = "1";
            objhxjc.Speed2 = "40";
            objhxjc.BeginV40 = "50";
            objhxjc.EndV40 = "30";
            objhxjc.BeginV25 = "35";
            objhxjc.EndV25 = "15";
            objhxjc.TheoretialTime40 = objini.ReadValue("汽油恒加载检定", "40km/h理论滑行时间");
            objhxjc.TheoretialTime25 =objini.ReadValue("汽油恒加载检定", "25km/h理论滑行时间");
            objhxjc.ActualTime40 = objini.ReadValue("汽油恒加载检定", "40km/h实际滑行时间");
            objhxjc.ActualTime25 = objini.ReadValue("汽油恒加载检定", "25km/h实际滑行时间");
            objhxjc.RatioResult40 = objini.ReadValue("汽油恒加载检定", "40km/h相对误差");
            objhxjc.RatioResult25 = objini.ReadValue("汽油恒加载检定", "25km/h相对误差");
            objhxjc.JudgeResult40 = objini.ReadValue("汽油恒加载检定", "40km/h判定").Contains("不合格") ? "0" : "1";
            objhxjc.JudgeResult25 = objini.ReadValue("汽油恒加载检定", "25km/h判定").Contains("不合格") ? "0" : "1";
            objhxjc.nJudgeResult = "1";
            objhxjc.Checker = skinCom_czy.Text;
            MessageBox.Show(m_mainform.objbass.uploadhxjc(objhxjc));
        }
        public string exchangeFtoSTR(string data)
        {
            string jieguo = "";
            float fjieguo = 0;
            float.TryParse(jieguo, out fjieguo);
            jieguo = (fjieguo * 1000f).ToString("0");
            return jieguo;
        }
        private void button6_Click(object sender, EventArgs e)
        {
            objgcsjnz.szCheckType = "2";
            objgcsjnz.icount = objgcsjnz.stringRpt.Count;
            string smexshow = m_mainform.objbass.upzjgcsj(objgcsjnz);
            if (smexshow.Length>1)
            {
                MessageBox.Show(smexshow); 
            }

            iniclass objini = new iniclass();
            objini.Ini(System.Windows.Forms.Application.StartupPath + "\\设备检定结果.ini");

            string sdata;
            DateTime dtdata;
            sdata = objini.ReadValue("附加损失功率", "检定时间");
            DateTime.TryParse(sdata, out dtdata);
            if (dtdata.ToString("yyyyMMdd") != DateTime.Now.ToString("yyyyMMdd"))
            {
                MessageBox.Show("该检定时间不是当天");
                return;
            }
            model.尾气自检.fjgl objfjgl = new model.尾气自检.fjgl();
            objfjgl.scyqy = "1";
            objfjgl.CheckDate = DateTime.Now.ToString("yyyy-MM-dd");
            objfjgl.PLTimeStart = objini.ReadValue("附加损失功率", "滑行开始时间");
            objfjgl.SlideTimeEnd = objini.ReadValue("附加损失功率", "滑行结束时间");
            objfjgl.Checker = skinCom_czy.Text;
            objfjgl.DIW = objini.ReadValue("附加损失功率", "惯量");
            objfjgl.PLHP40 = objini.ReadValue("附加损失功率", "40内阻");
            objfjgl.PLHP25 = objini.ReadValue("附加损失功率", "25内阻");
            objfjgl.ACDT25 = exchangeFtoSTR(objini.ReadValue("附加损失功率", "25滑行时间"));
            objfjgl.ACDT40 = exchangeFtoSTR(objini.ReadValue("附加损失功率", "40滑行时间"));
            objfjgl.CheckJudge = objini.ReadValue("附加损失功率", "40判定").Contains("不合格") ? "0" : "1";
            MessageBox.Show(m_mainform.objbass.uploadzj(objfjgl));
        }

        private void button7_Click(object sender, EventArgs e)
        {
            m_mainform.DAC.Lift(true);
        }
        private void button8_Click(object sender, EventArgs e)
        {
            m_mainform.DAC.Lift(false);
		}
		private void bt_scbd_Click(object sender, EventArgs e)
        {
            float fnz40, fnz25 = 0;
            model.尾气自检.JDhuaxing objhuaxing = new model.尾气自检.JDhuaxing();
            iniclass objini = new iniclass();
            objini.Ini(System.Windows.Forms.Application.StartupPath + "\\设备检定结果.ini");
            float.TryParse(objini.ReadValue("附加损失功率", "40内阻"), out fnz40);
            float.TryParse(objini.ReadValue("附加损失功率", "25内阻"), out fnz25);
            objhuaxing.hxqj1="50-30";
            objhuaxing.hxqj2 = "35-15";
            objhuaxing.jzgl1 = objini.ReadValue("汽油恒加载检定", "设置功率");
            objhuaxing.jzgl2 = objini.ReadValue("汽油恒加载检定", "设置功率");
            objhuaxing.jsgl1 = fnz40.ToString("0.00");
            objhuaxing.jsgl2 = fnz25.ToString("0.00");
            objhuaxing.hxsj1 = objini.ReadValue("汽油恒加载检定", "40km/h实际滑行时间");
            objhuaxing.hxsj2 = objini.ReadValue("汽油恒加载检定", "25km/h实际滑行时间");
            objhuaxing.llsj1 = objini.ReadValue("汽油恒加载检定", "40km/h理论滑行时间");
            objhuaxing.llsj2 = objini.ReadValue("汽油恒加载检定", "25km/h理论滑行时间");
            objhuaxing.wc1=objini.ReadValue("汽油恒加载检定", "40km/h相对误差");
            objhuaxing.wc2 = objini.ReadValue("汽油恒加载检定", "25km/h相对误差");
            objhuaxing.DIW = objini.ReadValue("汽油恒加载检定", "惯量");
            objhuaxing.CheckJudge1 = objini.ReadValue("汽油恒加载检定", "40km/h判定").Contains("不合格") ? "0" : "1";
            objhuaxing.CheckJudge2 = objini.ReadValue("汽油恒加载检定", "25km/h判定").Contains("不合格") ? "0" : "1";
            MessageBox.Show(m_mainform.objbass.uploadzj(objhuaxing));
        }

    }
}
